// https://leetcode.cn/problems/qIsx9U/
class MovingAverage {
public:
    /** Initialize your data structure here. */
    double sum = 0;
    int count = 0;
    vector<int> res;

    int real_size = 0;
    MovingAverage(int size) {
        real_size = size;
    }

    double next(int val) {
        sum += val;
        count++;
        res.push_back(val);
        if (count > real_size) {
            sum -= res[count - 1 - real_size];
            return sum / real_size;
        }

        return sum / count;
    }
};
